const { ccclass, property } = cc._decorator;
import WinNodeBase from '../WinNodeBase';
import SetCollisionPhysics from '../Game/SetCollisionPhysics';

@ccclass
export default class GameFailControl extends WinNodeBase {
    @property(cc.Node)
    GameRootNode: cc.Node = null;
    @property(cc.Node)
    ObjectNode: cc.Node = null;
    @property({
        type: [cc.Component.EventHandler],
        tooltip: "游戏结束"
    })
    DieOverEvents: Array<cc.Component.EventHandler> = [];

    resurgence() {
        this.mainClose();
        //重新初始化一个Hero
        let control = this.ObjectNode.getComponent(SetCollisionPhysics);
        control.initHero();
        this.reSetHero();
    }
    adsShow(){
        //广告播放
    }
    gameOver() {
        this.mainClose();
        //加载游戏结束界面
        cc.Component.EventHandler.emitEvents(this.DieOverEvents, {
            target: this,
        });
    }
    //重置Hero属性
    private reSetHero() {
        let detail = gameHelper.getInstance().heroDetail;
        let heroM = HeroManager.getInstance();
        heroM.runSpeed = detail.RunSpeed;
        heroM.jumpSpeed = detail.JumpSpeed;
        heroM.lifeMax = heroM.life = detail.Life;
        heroM.lifeRegain = detail.LifeRe;
        heroM.CommonImmunity = detail.ArmorA;
        heroM.AttributeImmunity = detail.ArmorC;
        heroM.damageAttack = detail.Damage;
        heroM.ReSetLife();
    }
}
